package com.yiyi.credit.manage.sso.mapper;

import com.yiyi.credit.manage.sso.common.constants.PaginationConstants;
import com.yiyi.credit.manage.sso.common.page.PageUtils;
import org.apache.commons.lang.StringUtils;

import java.util.Map;


public class SysRoleSqlProvider {

    //查询表
    private String fromInfo = " from sys_role ";


    public String queryForPage(Map<String, Object> paramMap) {
        String selectFiled = " id,sys_id sysId,role_name roleName ";

        return PageUtils.getPageCommonSql(selectFiled, fromInfo, whereSql(paramMap), "id")
                + PaginationConstants.LIMIT_SQL;
    }


    public String queryCount(Map<String, Object> paramMap) {
        String countFiled = " count(id) count ";

        return PageUtils.getPageCountSql(countFiled, fromInfo, whereSql(paramMap));
    }


    private String whereSql(Map<String, Object> paramMap) {
        StringBuilder sqlBuilder = new StringBuilder();
        sqlBuilder.append(" WHERE 1 = 1 ");
        if (null != paramMap.get("sysInfoId")
                && StringUtils.isNotBlank(String.valueOf(paramMap.get("sysInfoId")))) {
            sqlBuilder.append(" AND sys_id = #{sysInfoId} ");
        }
        return sqlBuilder.toString();
    }


}
